
import 'package:trade/common/util/ai_json/ai_json.dart';

class MarketDataBean {

  num amount;
  num vol;
  num low;
  num high;
  num open;
  num close;
  num change;
  MarketDataBean({
   this.amount = 0.0,
    this.vol = 0.0,
    this.low = 0.0,
    this.high = 0.0,
    this.open = 0.0,
    this.close = 0.0,
    this.change = 0.0
  });

  factory MarketDataBean.fromJson(Map<String, dynamic> json) {
    AiJson aJson = AiJson(json);
    double op = aJson.getNum("open").toDouble();
    double cl = aJson.getNum("close").toDouble();
    double ch = (cl - op)/op;
    return MarketDataBean(
      amount: aJson.getNum("amount"),
      vol: aJson.getNum("vol"),
      low: aJson.getNum("low"),
      high: aJson.getNum("high"),
      open: op,
      close: cl,
      change: ch
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['amount'] = this.amount;
    data['vol'] = this.vol;
    data['low'] = this.low;
    data['high'] = this.high;
    data['open'] = this.open;
    data['close'] = this.close;
    data['change'] = this.change;
    return data;
  }

}